namespace SolidMvvmLite {
	/// <summary>
	///     Derive your view model from this class if you need the option of saving your
	///     work before being disposed or of denying the ability to be disposed.
	/// </summary>
	public abstract class CloseableViewModelBase : ViewModelBase {
		bool canCloseCalled;

		protected CloseableViewModelBase(IMessageReporter messageReporter) : base(messageReporter) {}

		public override void Dispose() {
			try {
				base.Dispose();
			}
			finally {
				if (!canCloseCalled)
					throw new CleanupException("CanClose not called on view model of type '" + GetType() + "' before calling Dispose.", null);
			}
		}

		public virtual bool CanClose() {
			canCloseCalled = true;
			return true;
		}

		public void SuppressCanClose() {
			canCloseCalled = true;
		}
	}
}
